/**
 * Created with JetBrains WebStorm.
 * User: denglingcong
 * Date: 14-11-3
 * Time: 下午4:29
 * To change this template use File | Settings | File Templates.
 */

define(["app"], function(app) {
    var deps = ["$http", "BaseService"];

    function resource($http, BaseService) {
        return initSpaceResource($http,BaseService.restfulUrl + "category/");
    }
    var postHeader = {
        "Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"
    };
    function initSpaceResource($http,categoryUrl){
        return {
            /**
             * 查询类别
             * @param type
             * @param pageNo
             * @param pageSize
             * @returns {*|Object}
             */
            queryCategory:function(type,pageNo,pageSize){
                return $http.get(categoryUrl+'queryCategory',{
                    params:{
                        type:type,
                        pageNo:pageNo,
                        pageSize:pageSize
                    }
                });
            },
            /**
             * 删除类别
             * @param categoryIds
             * @returns {*|Object}
             */
            deleteCategory:function(categoryIds){
                return $http.post(categoryUrl+"deleteCategory",{
                    categoryIds:categoryIds
                },{
                    headers: postHeader
                });
            },
            /**
             * 移动类别
             * @param categoryIds
             * @param action 0上移 1下移
             * @returns {*|Object}
             */
            moveCategory:function(categoryIds,action){
                return $http.post(categoryUrl+"moveCategory",{
                    categoryIds : categoryIds,
                    action : action
                },{
                    headers: postHeader
                });
            },

            /**
             * 保存类别
             * @param categoryName
             * @param type
             * @returns {*|Object}
             */
            saveCategory:function(categoryName,type){
                return $http.get(categoryUrl+"saveCategory",{
                    params:{
                        categoryName:categoryName,
                        type:type
                    }
                });
            },

            /**
             * 更新类别
             * @param categoryName
             * @param categoryId
             * @returns {*|Object}
             */
            updateCategory:function(categoryName,categoryId){
                return $http.get(categoryUrl+"updateCategory",{
                    params:{
                        categoryName:categoryName,
                        categoryId:categoryId
                    }
                });
            },

            queryCategoryById:function(categoryId){
                return $http.get(categoryUrl+"queryCategoryById",{
                    params:{
                        categoryId:categoryId
                    }
                });
            },

            /**
             * 获取个数
             * @param categoryType
             * @returns {*|Object}
             */
            getCountBytype:function(categoryType){
                return $http.get(categoryUrl+"getCountBytype",{
                    params:{
                        type:categoryType
                    }
                });
            }
        };
    }
    resource.$inject = deps;
    app.lazy.factory("CategoryResource", resource);
});
